package cn.kooki.app.duobao.util.manager;

import android.database.Observable;

/**
 * Created by xiong on 2015/12/12.
 */
public class CartChangeObservable extends Observable<CartObserver> {

    public void notifyChanged(int count) {
        synchronized(mObservers) {

            System.out.println(count);
            for (int i = mObservers.size() - 1; i >= 0; i--) {
                mObservers.get(i).onChanged(count);
            }
        }
    }

    public void notifyCheckChanged(int count,boolean isCancelEditing ) {
        synchronized(mObservers) {
            // since onChanged() is implemented by the app, it could do anything, including
            // removing itself from {@link mObservers} - and that could cause problems if
            // an iterator is used on the ArrayList {@link mObservers}.
            // to avoid such problems, just march thru the list in the reverse order.
            for (int i = mObservers.size() - 1; i >= 0; i--) {
                mObservers.get(i).onCheckedChange(count,isCancelEditing);

            }
        }
    }

    public void notifyCartChange() {
        synchronized(mObservers) {
            // since onChanged() is implemented by the app, it could do anything, including
            // removing itself from {@link mObservers} - and that could cause problems if
            // an iterator is used on the ArrayList {@link mObservers}.
            // to avoid such problems, just march thru the list in the reverse order.
            for (int i = mObservers.size() - 1; i >= 0; i--) {
                mObservers.get(i).onCartsChange();
            }
        }
    }
}
